﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DLL.Entities;
using System.Xml;
using System.Xml.Serialization; 


namespace MIS
{
    public partial class MIS_Form : Form
    {
        Radar Missile = new Radar();
        int nummiss = 50;

        public MIS_Form()
        {
            InitializeComponent();
            
        }

        private void MIS_Form_Load(object sender, EventArgs e)
        {
            

        }

        private void btnFire_Click(object sender, EventArgs e)
        {
            int num = RandomNumber(0, 100);

            if (num < 50)
            {
                textBox2.Text = "Hit!";
                nummiss--;
                textBox1.Text = Convert.ToString(nummiss);                
            }
            else
            {
                textBox2.Text = "Miss!";
                nummiss--;
                textBox1.Text = Convert.ToString(nummiss);
            }
            if (nummiss == 0)
            {
                textBox2.Text = "Empty";
                btnFire.Enabled = false;
            }
        }
         private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                XmlReader reader2 = new XmlTextReader("../../../Missle.xml");
                XmlSerializer serializer2 = new XmlSerializer(typeof(Radar));
                Missile = (Radar)serializer2.Deserialize(reader2);
                reader2.Close();
            }
            catch (Exception ex) 
            {

            }
        }
        private int RandomNumber(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max); 
        }
    }    
}
